home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / info / lispref.info-6.z / lispref.info-6
Encoding:
GNU Info File  |  1998-05-21  |  49.3 KB  |  1,333 lines

  1. This is Info file ../../info/lispref.info, produced by Makeinfo version
  2. 1.68 from the input file lispref.texi.
  3.  
  4.    Edition History:
  5.  
  6.    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
  7. Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
  8. Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
  9. XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
  10. GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
  11. Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
  12. Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
  13. Reference Manual (for 19.15 and 20.1, 20.2) v3.2, April, May 1997
  14.  
  15.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
  16. Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
  17. Copyright (C) 1995, 1996 Ben Wing.
  18.  
  19.    Permission is granted to make and distribute verbatim copies of this
  20. manual provided the copyright notice and this permission notice are
  21. preserved on all copies.
  22.  
  23.    Permission is granted to copy and distribute modified versions of
  24. this manual under the conditions for verbatim copying, provided that the
  25. entire resulting derived work is distributed under the terms of a
  26. permission notice identical to this one.
  27.  
  28.    Permission is granted to copy and distribute translations of this
  29. manual into another language, under the above conditions for modified
  30. versions, except that this permission notice may be stated in a
  31. translation approved by the Foundation.
  32.  
  33.    Permission is granted to copy and distribute modified versions of
  34. this manual under the conditions for verbatim copying, provided also
  35. that the section entitled "GNU General Public License" is included
  36. exactly as in the original, and provided that the entire resulting
  37. derived work is distributed under the terms of a permission notice
  38. identical to this one.
  39.  
  40.    Permission is granted to copy and distribute translations of this
  41. manual into another language, under the above conditions for modified
  42. versions, except that the section entitled "GNU General Public License"
  43. may be included in a translation approved by the Free Software
  44. Foundation instead of in the original English.
  45.  
  46. 
  47. File: lispref.info,  Node: List Elements,  Next: Building Lists,  Prev: List-related Predicates,  Up: Lists
  48.  
  49. Accessing Elements of Lists
  50. ===========================
  51.  
  52.  - Function: car CONS-CELL
  53.      This function returns the value pointed to by the first pointer of
  54.      the cons cell CONS-CELL.  Expressed another way, this function
  55.      returns the CAR of CONS-CELL.
  56.  
  57.      As a special case, if CONS-CELL is `nil', then `car' is defined to
  58.      return `nil'; therefore, any list is a valid argument for `car'.
  59.      An error is signaled if the argument is not a cons cell or `nil'.
  60.  
  61.           (car '(a b c))
  62.                => a
  63.           (car '())
  64.                => nil
  65.  
  66.  - Function: cdr CONS-CELL
  67.      This function returns the value pointed to by the second pointer of
  68.      the cons cell CONS-CELL.  Expressed another way, this function
  69.      returns the CDR of CONS-CELL.
  70.  
  71.      As a special case, if CONS-CELL is `nil', then `cdr' is defined to
  72.      return `nil'; therefore, any list is a valid argument for `cdr'.
  73.      An error is signaled if the argument is not a cons cell or `nil'.
  74.  
  75.           (cdr '(a b c))
  76.                => (b c)
  77.           (cdr '())
  78.                => nil
  79.  
  80.  - Function: car-safe OBJECT
  81.      This function lets you take the CAR of a cons cell while avoiding
  82.      errors for other data types.  It returns the CAR of OBJECT if
  83.      OBJECT is a cons cell, `nil' otherwise.  This is in contrast to
  84.      `car', which signals an error if OBJECT is not a list.
  85.  
  86.           (car-safe OBJECT)
  87.           ==
  88.           (let ((x OBJECT))
  89.             (if (consp x)
  90.                 (car x)
  91.               nil))
  92.  
  93.  - Function: cdr-safe OBJECT
  94.      This function lets you take the CDR of a cons cell while avoiding
  95.      errors for other data types.  It returns the CDR of OBJECT if
  96.      OBJECT is a cons cell, `nil' otherwise.  This is in contrast to
  97.      `cdr', which signals an error if OBJECT is not a list.
  98.  
  99.           (cdr-safe OBJECT)
  100.           ==
  101.           (let ((x OBJECT))
  102.             (if (consp x)
  103.                 (cdr x)
  104.               nil))
  105.  
  106.  - Function: nth N LIST
  107.      This function returns the Nth element of LIST.  Elements are
  108.      numbered starting with zero, so the CAR of LIST is element number
  109.      zero.  If the length of LIST is N or less, the value is `nil'.
  110.  
  111.      If N is negative, `nth' returns the first element of LIST.
  112.  
  113.           (nth 2 '(1 2 3 4))
  114.                => 3
  115.           (nth 10 '(1 2 3 4))
  116.                => nil
  117.           (nth -3 '(1 2 3 4))
  118.                => 1
  119.           
  120.           (nth n x) == (car (nthcdr n x))
  121.  
  122.  - Function: nthcdr N LIST
  123.      This function returns the Nth CDR of LIST.  In other words, it
  124.      removes the first N links of LIST and returns what follows.
  125.  
  126.      If N is zero or negative, `nthcdr' returns all of LIST.  If the
  127.      length of LIST is N or less, `nthcdr' returns `nil'.
  128.  
  129.           (nthcdr 1 '(1 2 3 4))
  130.                => (2 3 4)
  131.           (nthcdr 10 '(1 2 3 4))
  132.                => nil
  133.           (nthcdr -3 '(1 2 3 4))
  134.                => (1 2 3 4)
  135.  
  136.    Many convenience functions are provided to make it easier for you to
  137. access particular elements in a nested list.  All of these can be
  138. rewritten in terms of the functions just described.
  139.  
  140.  - Function: caar CONS-CELL
  141.  - Function: cadr CONS-CELL
  142.  - Function: cdar CONS-CELL
  143.  - Function: cddr CONS-CELL
  144.  - Function: caaar CONS-CELL
  145.  - Function: caadr CONS-CELL
  146.  - Function: cadar CONS-CELL
  147.  - Function: caddr CONS-CELL
  148.  - Function: cdaar CONS-CELL
  149.  - Function: cdadr CONS-CELL
  150.  - Function: cddar CONS-CELL
  151.  - Function: cdddr CONS-CELL
  152.  - Function: caaaar CONS-CELL
  153.  - Function: caaadr CONS-CELL
  154.  - Function: caadar CONS-CELL
  155.  - Function: caaddr CONS-CELL
  156.  - Function: cadaar CONS-CELL
  157.  - Function: cadadr CONS-CELL
  158.  - Function: caddar CONS-CELL
  159.  - Function: cadddr CONS-CELL
  160.  - Function: cdaaar CONS-CELL
  161.  - Function: cdaadr CONS-CELL
  162.  - Function: cdadar CONS-CELL
  163.  - Function: cdaddr CONS-CELL
  164.  - Function: cddaar CONS-CELL
  165.  - Function: cddadr CONS-CELL
  166.  - Function: cdddar CONS-CELL
  167.  - Function: cddddr CONS-CELL
  168.      Each of these functions is equivalent to one or more applications
  169.      of `car' and/or `cdr'.  For example,
  170.  
  171.           (cadr x)
  172.  
  173.      is equivalent to
  174.  
  175.           (car (cdr x))
  176.  
  177.      and
  178.  
  179.           (cdaddr x)
  180.  
  181.      is equivalent to
  182.  
  183.           (cdr (car (cdr (cdr x))))
  184.  
  185.      That is to say, read the a's and d's from right to left and apply
  186.      a `car' or `cdr' for each a or d found, respectively.
  187.  
  188.  - Function: first LIST
  189.      This is equivalent to `(nth 0 LIST)', i.e. the first element of
  190.      LIST. (Note that this is also equivalent to `car'.)
  191.  
  192.  - Function: second LIST
  193.      This is equivalent to `(nth 1 LIST)', i.e. the second element of
  194.      LIST.
  195.  
  196.  - Function: third LIST
  197.  - Function: fourth LIST
  198.  - Function: fifth LIST
  199.  - Function: sixth LIST
  200.  - Function: seventh LIST
  201.  - Function: eighth LIST
  202.  - Function: ninth LIST
  203.  - Function: tenth LIST
  204.      These are equivalent to `(nth 2 LIST)' through `(nth 9 LIST)'
  205.      respectively, i.e. the third through tenth elements of LIST.
  206.  
  207. 
  208. File: lispref.info,  Node: Building Lists,  Next: Modifying Lists,  Prev: List Elements,  Up: Lists
  209.  
  210. Building Cons Cells and Lists
  211. =============================
  212.  
  213.    Many functions build lists, as lists reside at the very heart of
  214. Lisp.  `cons' is the fundamental list-building function; however, it is
  215. interesting to note that `list' is used more times in the source code
  216. for Emacs than `cons'.
  217.  
  218.  - Function: cons OBJECT1 OBJECT2
  219.      This function is the fundamental function used to build new list
  220.      structure.  It creates a new cons cell, making OBJECT1 the CAR,
  221.      and OBJECT2 the CDR.  It then returns the new cons cell.  The
  222.      arguments OBJECT1 and OBJECT2 may be any Lisp objects, but most
  223.      often OBJECT2 is a list.
  224.  
  225.           (cons 1 '(2))
  226.                => (1 2)
  227.           (cons 1 '())
  228.                => (1)
  229.           (cons 1 2)
  230.                => (1 . 2)
  231.  
  232.      `cons' is often used to add a single element to the front of a
  233.      list.  This is called "consing the element onto the list".  For
  234.      example:
  235.  
  236.           (setq list (cons newelt list))
  237.  
  238.      Note that there is no conflict between the variable named `list'
  239.      used in this example and the function named `list' described below;
  240.      any symbol can serve both purposes.
  241.  
  242.  - Function: list &rest OBJECTS
  243.      This function creates a list with OBJECTS as its elements.  The
  244.      resulting list is always `nil'-terminated.  If no OBJECTS are
  245.      given, the empty list is returned.
  246.  
  247.           (list 1 2 3 4 5)
  248.                => (1 2 3 4 5)
  249.           (list 1 2 '(3 4 5) 'foo)
  250.                => (1 2 (3 4 5) foo)
  251.           (list)
  252.                => nil
  253.  
  254.  - Function: make-list LENGTH OBJECT
  255.      This function creates a list of length LENGTH, in which all the
  256.      elements have the identical value OBJECT.  Compare `make-list'
  257.      with `make-string' (*note Creating Strings::.).
  258.  
  259.           (make-list 3 'pigs)
  260.                => (pigs pigs pigs)
  261.           (make-list 0 'pigs)
  262.                => nil
  263.  
  264.  - Function: append &rest SEQUENCES
  265.      This function returns a list containing all the elements of
  266.      SEQUENCES.  The SEQUENCES may be lists, vectors, or strings, but
  267.      the last one should be a list.  All arguments except the last one
  268.      are copied, so none of them are altered.
  269.  
  270.      More generally, the final argument to `append' may be any Lisp
  271.      object.  The final argument is not copied or converted; it becomes
  272.      the CDR of the last cons cell in the new list.  If the final
  273.      argument is itself a list, then its elements become in effect
  274.      elements of the result list.  If the final element is not a list,
  275.      the result is a "dotted list" since its final CDR is not `nil' as
  276.      required in a true list.
  277.  
  278.      See `nconc' in *Note Rearrangement::, for a way to join lists with
  279.      no copying.
  280.  
  281.      Here is an example of using `append':
  282.  
  283.           (setq trees '(pine oak))
  284.                => (pine oak)
  285.           (setq more-trees (append '(maple birch) trees))
  286.                => (maple birch pine oak)
  287.           
  288.           trees
  289.                => (pine oak)
  290.           more-trees
  291.                => (maple birch pine oak)
  292.           (eq trees (cdr (cdr more-trees)))
  293.                => t
  294.  
  295.      You can see how `append' works by looking at a box diagram.  The
  296.      variable `trees' is set to the list `(pine oak)' and then the
  297.      variable `more-trees' is set to the list `(maple birch pine oak)'.
  298.      However, the variable `trees' continues to refer to the original
  299.      list:
  300.  
  301.           more-trees                trees
  302.           |                           |
  303.           |     ___ ___      ___ ___   -> ___ ___      ___ ___
  304.            --> |___|___|--> |___|___|--> |___|___|--> |___|___|--> nil
  305.                  |            |            |            |
  306.                  |            |            |            |
  307.                   --> maple    -->birch     --> pine     --> oak
  308.  
  309.      An empty sequence contributes nothing to the value returned by
  310.      `append'.  As a consequence of this, a final `nil' argument forces
  311.      a copy of the previous argument.
  312.  
  313.           trees
  314.                => (pine oak)
  315.           (setq wood (append trees ()))
  316.                => (pine oak)
  317.           wood
  318.                => (pine oak)
  319.           (eq wood trees)
  320.                => nil
  321.  
  322.      This once was the usual way to copy a list, before the function
  323.      `copy-sequence' was invented.  *Note Sequences Arrays Vectors::.
  324.  
  325.      With the help of `apply', we can append all the lists in a list of
  326.      lists:
  327.  
  328.           (apply 'append '((a b c) nil (x y z) nil))
  329.                => (a b c x y z)
  330.  
  331.      If no SEQUENCES are given, `nil' is returned:
  332.  
  333.           (append)
  334.                => nil
  335.  
  336.      Here are some examples where the final argument is not a list:
  337.  
  338.           (append '(x y) 'z)
  339.                => (x y . z)
  340.           (append '(x y) [z])
  341.                => (x y . [z])
  342.  
  343.      The second example shows that when the final argument is a
  344.      sequence but not a list, the sequence's elements do not become
  345.      elements of the resulting list.  Instead, the sequence becomes the
  346.      final CDR, like any other non-list final argument.
  347.  
  348.      The `append' function also allows integers as arguments.  It
  349.      converts them to strings of digits, making up the decimal print
  350.      representation of the integer, and then uses the strings instead
  351.      of the original integers.  *Don't use this feature; we plan to
  352.      eliminate it.  If you already use this feature, change your
  353.      programs now!*  The proper way to convert an integer to a decimal
  354.      number in this way is with `format' (*note Formatting Strings::.)
  355.      or `number-to-string' (*note String Conversion::.).
  356.  
  357.  - Function: reverse LIST
  358.      This function creates a new list whose elements are the elements of
  359.      LIST, but in reverse order.  The original argument LIST is *not*
  360.      altered.
  361.  
  362.           (setq x '(1 2 3 4))
  363.                => (1 2 3 4)
  364.           (reverse x)
  365.                => (4 3 2 1)
  366.           x
  367.                => (1 2 3 4)
  368.  
  369. 
  370. File: lispref.info,  Node: Modifying Lists,  Next: Sets And Lists,  Prev: Building Lists,  Up: Lists
  371.  
  372. Modifying Existing List Structure
  373. =================================
  374.  
  375.    You can modify the CAR and CDR contents of a cons cell with the
  376. primitives `setcar' and `setcdr'.
  377.  
  378.      Common Lisp note: Common Lisp uses functions `rplaca' and `rplacd'
  379.      to alter list structure; they change structure the same way as
  380.      `setcar' and `setcdr', but the Common Lisp functions return the
  381.      cons cell while `setcar' and `setcdr' return the new CAR or CDR.
  382.  
  383. * Menu:
  384.  
  385. * Setcar::          Replacing an element in a list.
  386. * Setcdr::          Replacing part of the list backbone.
  387.                       This can be used to remove or add elements.
  388. * Rearrangement::   Reordering the elements in a list; combining lists.
  389.  
  390. 
  391. File: lispref.info,  Node: Setcar,  Next: Setcdr,  Up: Modifying Lists
  392.  
  393. Altering List Elements with `setcar'
  394. ------------------------------------
  395.  
  396.    Changing the CAR of a cons cell is done with `setcar'.  When used on
  397. a list, `setcar' replaces one element of a list with a different
  398. element.
  399.  
  400.  - Function: setcar CONS OBJECT
  401.      This function stores OBJECT as the new CAR of CONS, replacing its
  402.      previous CAR.  It returns the value OBJECT.  For example:
  403.  
  404.           (setq x '(1 2))
  405.                => (1 2)
  406.           (setcar x 4)
  407.                => 4
  408.           x
  409.                => (4 2)
  410.  
  411.    When a cons cell is part of the shared structure of several lists,
  412. storing a new CAR into the cons changes one element of each of these
  413. lists.  Here is an example:
  414.  
  415.      ;; Create two lists that are partly shared.
  416.      (setq x1 '(a b c))
  417.           => (a b c)
  418.      (setq x2 (cons 'z (cdr x1)))
  419.           => (z b c)
  420.      
  421.      ;; Replace the CAR of a shared link.
  422.      (setcar (cdr x1) 'foo)
  423.           => foo
  424.      x1                           ; Both lists are changed.
  425.           => (a foo c)
  426.      x2
  427.           => (z foo c)
  428.      
  429.      ;; Replace the CAR of a link that is not shared.
  430.      (setcar x1 'baz)
  431.           => baz
  432.      x1                           ; Only one list is changed.
  433.           => (baz foo c)
  434.      x2
  435.           => (z foo c)
  436.  
  437.    Here is a graphical depiction of the shared structure of the two
  438. lists in the variables `x1' and `x2', showing why replacing `b' changes
  439. them both:
  440.  
  441.              ___ ___        ___ ___      ___ ___
  442.      x1---> |___|___|----> |___|___|--> |___|___|--> nil
  443.               |        -->   |            |
  444.               |       |      |            |
  445.                --> a  |       --> b        --> c
  446.                       |
  447.             ___ ___   |
  448.      x2--> |___|___|--
  449.              |
  450.              |
  451.               --> z
  452.  
  453.    Here is an alternative form of box diagram, showing the same
  454. relationship:
  455.  
  456.      x1:
  457.       --------------       --------------       --------------
  458.      | car   | cdr  |     | car   | cdr  |     | car   | cdr  |
  459.      |   a   |   o------->|   b   |   o------->|   c   |  nil |
  460.      |       |      |  -->|       |      |     |       |      |
  461.       --------------  |    --------------       --------------
  462.                       |
  463.      x2:              |
  464.       --------------  |
  465.      | car   | cdr  | |
  466.      |   z   |   o----
  467.      |       |      |
  468.       --------------
  469.  
  470. 
  471. File: lispref.info,  Node: Setcdr,  Next: Rearrangement,  Prev: Setcar,  Up: Modifying Lists
  472.  
  473. Altering the CDR of a List
  474. --------------------------
  475.  
  476.    The lowest-level primitive for modifying a CDR is `setcdr':
  477.  
  478.  - Function: setcdr CONS OBJECT
  479.      This function stores OBJECT as the new CDR of CONS, replacing its
  480.      previous CDR.  It returns the value OBJECT.
  481.  
  482.    Here is an example of replacing the CDR of a list with a different
  483. list.  All but the first element of the list are removed in favor of a
  484. different sequence of elements.  The first element is unchanged,
  485. because it resides in the CAR of the list, and is not reached via the
  486. CDR.
  487.  
  488.      (setq x '(1 2 3))
  489.           => (1 2 3)
  490.      (setcdr x '(4))
  491.           => (4)
  492.      x
  493.           => (1 4)
  494.  
  495.    You can delete elements from the middle of a list by altering the
  496. CDRs of the cons cells in the list.  For example, here we delete the
  497. second element, `b', from the list `(a b c)', by changing the CDR of
  498. the first cell:
  499.  
  500.      (setq x1 '(a b c))
  501.           => (a b c)
  502.      (setcdr x1 (cdr (cdr x1)))
  503.           => (c)
  504.      x1
  505.           => (a c)
  506.  
  507.    Here is the result in box notation:
  508.  
  509.                         --------------------
  510.                        |                    |
  511.       --------------   |   --------------   |    --------------
  512.      | car   | cdr  |  |  | car   | cdr  |   -->| car   | cdr  |
  513.      |   a   |   o-----   |   b   |   o-------->|   c   |  nil |
  514.      |       |      |     |       |      |      |       |      |
  515.       --------------       --------------        --------------
  516.  
  517. The second cons cell, which previously held the element `b', still
  518. exists and its CAR is still `b', but it no longer forms part of this
  519. list.
  520.  
  521.    It is equally easy to insert a new element by changing CDRs:
  522.  
  523.      (setq x1 '(a b c))
  524.           => (a b c)
  525.      (setcdr x1 (cons 'd (cdr x1)))
  526.           => (d b c)
  527.      x1
  528.           => (a d b c)
  529.  
  530.    Here is this result in box notation:
  531.  
  532.      --------------        -------------       -------------
  533.      | car  | cdr   |      | car  | cdr  |     | car  | cdr  |
  534.      |   a  |   o   |   -->|   b  |   o------->|   c  |  nil |
  535.      |      |   |   |  |   |      |      |     |      |      |
  536.       --------- | --   |    -------------       -------------
  537.                 |      |
  538.           -----         --------
  539.          |                      |
  540.          |    ---------------   |
  541.          |   | car   | cdr   |  |
  542.           -->|   d   |   o------
  543.              |       |       |
  544.               ---------------
  545.  
  546. 
  547. File: lispref.info,  Node: Rearrangement,  Prev: Setcdr,  Up: Modifying Lists
  548.  
  549. Functions that Rearrange Lists
  550. ------------------------------
  551.  
  552.    Here are some functions that rearrange lists "destructively" by
  553. modifying the CDRs of their component cons cells.  We call these
  554. functions "destructive" because they chew up the original lists passed
  555. to them as arguments, to produce a new list that is the returned value.
  556.  
  557.    See `delq', in *Note Sets And Lists::, for another function that
  558. modifies cons cells.
  559.  
  560.  - Function: nconc &rest LISTS
  561.      This function returns a list containing all the elements of LISTS.
  562.      Unlike `append' (*note Building Lists::.), the LISTS are *not*
  563.      copied.  Instead, the last CDR of each of the LISTS is changed to
  564.      refer to the following list.  The last of the LISTS is not
  565.      altered.  For example:
  566.  
  567.           (setq x '(1 2 3))
  568.                => (1 2 3)
  569.           (nconc x '(4 5))
  570.                => (1 2 3 4 5)
  571.           x
  572.                => (1 2 3 4 5)
  573.  
  574.      Since the last argument of `nconc' is not itself modified, it is
  575.      reasonable to use a constant list, such as `'(4 5)', as in the
  576.      above example.  For the same reason, the last argument need not be
  577.      a list:
  578.  
  579.           (setq x '(1 2 3))
  580.                => (1 2 3)
  581.           (nconc x 'z)
  582.                => (1 2 3 . z)
  583.           x
  584.                => (1 2 3 . z)
  585.  
  586.      A common pitfall is to use a quoted constant list as a non-last
  587.      argument to `nconc'.  If you do this, your program will change
  588.      each time you run it!  Here is what happens:
  589.  
  590.           (defun add-foo (x)            ; We want this function to add
  591.             (nconc '(foo) x))           ;   `foo' to the front of its arg.
  592.  
  593.           (symbol-function 'add-foo)
  594.                => (lambda (x) (nconc (quote (foo)) x))
  595.  
  596.           (setq xx (add-foo '(1 2)))    ; It seems to work.
  597.                => (foo 1 2)
  598.  
  599.           (setq xy (add-foo '(3 4)))    ; What happened?
  600.                => (foo 1 2 3 4)
  601.  
  602.           (eq xx xy)
  603.                => t
  604.  
  605.           (symbol-function 'add-foo)
  606.                => (lambda (x) (nconc (quote (foo 1 2 3 4) x)))
  607.  
  608.  - Function: nreverse LIST
  609.      This function reverses the order of the elements of LIST.  Unlike
  610.      `reverse', `nreverse' alters its argument by reversing the CDRs in
  611.      the cons cells forming the list.  The cons cell that used to be
  612.      the last one in LIST becomes the first cell of the value.
  613.  
  614.      For example:
  615.  
  616.           (setq x '(1 2 3 4))
  617.                => (1 2 3 4)
  618.           x
  619.                => (1 2 3 4)
  620.           (nreverse x)
  621.                => (4 3 2 1)
  622.           ;; The cell that was first is now last.
  623.           x
  624.                => (1)
  625.  
  626.      To avoid confusion, we usually store the result of `nreverse' back
  627.      in the same variable which held the original list:
  628.  
  629.           (setq x (nreverse x))
  630.  
  631.      Here is the `nreverse' of our favorite example, `(a b c)',
  632.      presented graphically:
  633.  
  634.           Original list head:                       Reversed list:
  635.            -------------        -------------        ------------
  636.           | car  | cdr  |      | car  | cdr  |      | car | cdr  |
  637.           |   a  |  nil |<--   |   b  |   o  |<--   |   c |   o  |
  638.           |      |      |   |  |      |   |  |   |  |     |   |  |
  639.            -------------    |   --------- | -    |   -------- | -
  640.                             |             |      |            |
  641.                              -------------        ------------
  642.  
  643.  - Function: sort LIST PREDICATE
  644.      This function sorts LIST stably, though destructively, and returns
  645.      the sorted list.  It compares elements using PREDICATE.  A stable
  646.      sort is one in which elements with equal sort keys maintain their
  647.      relative order before and after the sort.  Stability is important
  648.      when successive sorts are used to order elements according to
  649.      different criteria.
  650.  
  651.      The argument PREDICATE must be a function that accepts two
  652.      arguments.  It is called with two elements of LIST.  To get an
  653.      increasing order sort, the PREDICATE should return `t' if the
  654.      first element is "less than" the second, or `nil' if not.
  655.  
  656.      The destructive aspect of `sort' is that it rearranges the cons
  657.      cells forming LIST by changing CDRs.  A nondestructive sort
  658.      function would create new cons cells to store the elements in their
  659.      sorted order.  If you wish to make a sorted copy without
  660.      destroying the original, copy it first with `copy-sequence' and
  661.      then sort.
  662.  
  663.      Sorting does not change the CARs of the cons cells in LIST; the
  664.      cons cell that originally contained the element `a' in LIST still
  665.      has `a' in its CAR after sorting, but it now appears in a
  666.      different position in the list due to the change of CDRs.  For
  667.      example:
  668.  
  669.           (setq nums '(1 3 2 6 5 4 0))
  670.                => (1 3 2 6 5 4 0)
  671.           (sort nums '<)
  672.                => (0 1 2 3 4 5 6)
  673.           nums
  674.                => (1 2 3 4 5 6)
  675.  
  676.      Note that the list in `nums' no longer contains 0; this is the same
  677.      cons cell that it was before, but it is no longer the first one in
  678.      the list.  Don't assume a variable that formerly held the argument
  679.      now holds the entire sorted list!  Instead, save the result of
  680.      `sort' and use that.  Most often we store the result back into the
  681.      variable that held the original list:
  682.  
  683.           (setq nums (sort nums '<))
  684.  
  685.      *Note Sorting::, for more functions that perform sorting.  See
  686.      `documentation' in *Note Accessing Documentation::, for a useful
  687.      example of `sort'.
  688.  
  689. 
  690. File: lispref.info,  Node: Sets And Lists,  Next: Association Lists,  Prev: Modifying Lists,  Up: Lists
  691.  
  692. Using Lists as Sets
  693. ===================
  694.  
  695.    A list can represent an unordered mathematical set--simply consider a
  696. value an element of a set if it appears in the list, and ignore the
  697. order of the list.  To form the union of two sets, use `append' (as
  698. long as you don't mind having duplicate elements).  Other useful
  699. functions for sets include `memq' and `delq', and their `equal'
  700. versions, `member' and `delete'.
  701.  
  702.      Common Lisp note: Common Lisp has functions `union' (which avoids
  703.      duplicate elements) and `intersection' for set operations, but
  704.      XEmacs Lisp does not have them.  You can write them in Lisp if you
  705.      wish.
  706.  
  707.  - Function: memq OBJECT LIST
  708.      This function tests to see whether OBJECT is a member of LIST.  If
  709.      it is, `memq' returns a list starting with the first occurrence of
  710.      OBJECT.  Otherwise, it returns `nil'.  The letter `q' in `memq'
  711.      says that it uses `eq' to compare OBJECT against the elements of
  712.      the list.  For example:
  713.  
  714.           (memq 'b '(a b c b a))
  715.                => (b c b a)
  716.           (memq '(2) '((1) (2)))    ; `(2)' and `(2)' are not `eq'.
  717.                => nil
  718.  
  719.  - Function: delq OBJECT LIST
  720.      This function destructively removes all elements `eq' to OBJECT
  721.      from LIST.  The letter `q' in `delq' says that it uses `eq' to
  722.      compare OBJECT against the elements of the list, like `memq'.
  723.  
  724.    When `delq' deletes elements from the front of the list, it does so
  725. simply by advancing down the list and returning a sublist that starts
  726. after those elements:
  727.  
  728.      (delq 'a '(a b c)) == (cdr '(a b c))
  729.  
  730.    When an element to be deleted appears in the middle of the list,
  731. removing it involves changing the CDRs (*note Setcdr::.).
  732.  
  733.      (setq sample-list '(a b c (4)))
  734.           => (a b c (4))
  735.      (delq 'a sample-list)
  736.           => (b c (4))
  737.      sample-list
  738.           => (a b c (4))
  739.      (delq 'c sample-list)
  740.           => (a b (4))
  741.      sample-list
  742.           => (a b (4))
  743.  
  744.    Note that `(delq 'c sample-list)' modifies `sample-list' to splice
  745. out the third element, but `(delq 'a sample-list)' does not splice
  746. anything--it just returns a shorter list.  Don't assume that a variable
  747. which formerly held the argument LIST now has fewer elements, or that
  748. it still holds the original list!  Instead, save the result of `delq'
  749. and use that.  Most often we store the result back into the variable
  750. that held the original list:
  751.  
  752.      (setq flowers (delq 'rose flowers))
  753.  
  754.    In the following example, the `(4)' that `delq' attempts to match
  755. and the `(4)' in the `sample-list' are not `eq':
  756.  
  757.      (delq '(4) sample-list)
  758.           => (a c (4))
  759.  
  760.    The following two functions are like `memq' and `delq' but use
  761. `equal' rather than `eq' to compare elements.  They are new in Emacs 19.
  762.  
  763.  - Function: member OBJECT LIST
  764.      The function `member' tests to see whether OBJECT is a member of
  765.      LIST, comparing members with OBJECT using `equal'.  If OBJECT is a
  766.      member, `member' returns a list starting with its first occurrence
  767.      in LIST.  Otherwise, it returns `nil'.
  768.  
  769.      Compare this with `memq':
  770.  
  771.           (member '(2) '((1) (2)))  ; `(2)' and `(2)' are `equal'.
  772.                => ((2))
  773.           (memq '(2) '((1) (2)))    ; `(2)' and `(2)' are not `eq'.
  774.                => nil
  775.           ;; Two strings with the same contents are `equal'.
  776.           (member "foo" '("foo" "bar"))
  777.                => ("foo" "bar")
  778.  
  779.  - Function: delete OBJECT LIST
  780.      This function destructively removes all elements `equal' to OBJECT
  781.      from LIST.  It is to `delq' as `member' is to `memq': it uses
  782.      `equal' to compare elements with OBJECT, like `member'; when it
  783.      finds an element that matches, it removes the element just as
  784.      `delq' would.  For example:
  785.  
  786.           (delete '(2) '((2) (1) (2)))
  787.                => '((1))
  788.  
  789.      Common Lisp note: The functions `member' and `delete' in XEmacs
  790.      Lisp are derived from Maclisp, not Common Lisp.  The Common Lisp
  791.      versions do not use `equal' to compare elements.
  792.  
  793.    See also the function `add-to-list', in *Note Setting Variables::,
  794. for another way to add an element to a list stored in a variable.
  795.  
  796. 
  797. File: lispref.info,  Node: Association Lists,  Next: Property Lists,  Prev: Sets And Lists,  Up: Lists
  798.  
  799. Association Lists
  800. =================
  801.  
  802.    An "association list", or "alist" for short, records a mapping from
  803. keys to values.  It is a list of cons cells called "associations": the
  804. CAR of each cell is the "key", and the CDR is the "associated value".(1)
  805.  
  806.    Here is an example of an alist.  The key `pine' is associated with
  807. the value `cones'; the key `oak' is associated with `acorns'; and the
  808. key `maple' is associated with `seeds'.
  809.  
  810.      '((pine . cones)
  811.        (oak . acorns)
  812.        (maple . seeds))
  813.  
  814.    The associated values in an alist may be any Lisp objects; so may the
  815. keys.  For example, in the following alist, the symbol `a' is
  816. associated with the number `1', and the string `"b"' is associated with
  817. the *list* `(2 3)', which is the CDR of the alist element:
  818.  
  819.      ((a . 1) ("b" 2 3))
  820.  
  821.    Sometimes it is better to design an alist to store the associated
  822. value in the CAR of the CDR of the element.  Here is an example:
  823.  
  824.      '((rose red) (lily white) (buttercup yellow))
  825.  
  826. Here we regard `red' as the value associated with `rose'.  One
  827. advantage of this method is that you can store other related
  828. information--even a list of other items--in the CDR of the CDR.  One
  829. disadvantage is that you cannot use `rassq' (see below) to find the
  830. element containing a given value.  When neither of these considerations
  831. is important, the choice is a matter of taste, as long as you are
  832. consistent about it for any given alist.
  833.  
  834.    Note that the same alist shown above could be regarded as having the
  835. associated value in the CDR of the element; the value associated with
  836. `rose' would be the list `(red)'.
  837.  
  838.    Association lists are often used to record information that you might
  839. otherwise keep on a stack, since new associations may be added easily to
  840. the front of the list.  When searching an association list for an
  841. association with a given key, the first one found is returned, if there
  842. is more than one.
  843.  
  844.    In XEmacs Lisp, it is *not* an error if an element of an association
  845. list is not a cons cell.  The alist search functions simply ignore such
  846. elements.  Many other versions of Lisp signal errors in such cases.
  847.  
  848.    Note that property lists are similar to association lists in several
  849. respects.  A property list behaves like an association list in which
  850. each key can occur only once.  *Note Property Lists::, for a comparison
  851. of property lists and association lists.
  852.  
  853.  - Function: assoc KEY ALIST
  854.      This function returns the first association for KEY in ALIST.  It
  855.      compares KEY against the alist elements using `equal' (*note
  856.      Equality Predicates::.).  It returns `nil' if no association in
  857.      ALIST has a CAR `equal' to KEY.  For example:
  858.  
  859.           (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
  860.                => ((pine . cones) (oak . acorns) (maple . seeds))
  861.           (assoc 'oak trees)
  862.                => (oak . acorns)
  863.           (cdr (assoc 'oak trees))
  864.                => acorns
  865.           (assoc 'birch trees)
  866.                => nil
  867.  
  868.      Here is another example, in which the keys and values are not
  869.      symbols:
  870.  
  871.           (setq needles-per-cluster
  872.                 '((2 "Austrian Pine" "Red Pine")
  873.                   (3 "Pitch Pine")
  874.                   (5 "White Pine")))
  875.           
  876.           (cdr (assoc 3 needles-per-cluster))
  877.                => ("Pitch Pine")
  878.           (cdr (assoc 2 needles-per-cluster))
  879.                => ("Austrian Pine" "Red Pine")
  880.  
  881.  - Function: rassoc VALUE ALIST
  882.      This function returns the first association with value VALUE in
  883.      ALIST.  It returns `nil' if no association in ALIST has a CDR
  884.      `equal' to VALUE.
  885.  
  886.      `rassoc' is like `assoc' except that it compares the CDR of each
  887.      ALIST association instead of the CAR.  You can think of this as
  888.      "reverse `assoc'", finding the key for a given value.
  889.  
  890.  - Function: assq KEY ALIST
  891.      This function is like `assoc' in that it returns the first
  892.      association for KEY in ALIST, but it makes the comparison using
  893.      `eq' instead of `equal'.  `assq' returns `nil' if no association
  894.      in ALIST has a CAR `eq' to KEY.  This function is used more often
  895.      than `assoc', since `eq' is faster than `equal' and most alists
  896.      use symbols as keys.  *Note Equality Predicates::.
  897.  
  898.           (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
  899.                => ((pine . cones) (oak . acorns) (maple . seeds))
  900.           (assq 'pine trees)
  901.                => (pine . cones)
  902.  
  903.      On the other hand, `assq' is not usually useful in alists where the
  904.      keys may not be symbols:
  905.  
  906.           (setq leaves
  907.                 '(("simple leaves" . oak)
  908.                   ("compound leaves" . horsechestnut)))
  909.           
  910.           (assq "simple leaves" leaves)
  911.                => nil
  912.           (assoc "simple leaves" leaves)
  913.                => ("simple leaves" . oak)
  914.  
  915.  - Function: rassq VALUE ALIST
  916.      This function returns the first association with value VALUE in
  917.      ALIST.  It returns `nil' if no association in ALIST has a CDR `eq'
  918.      to VALUE.
  919.  
  920.      `rassq' is like `assq' except that it compares the CDR of each
  921.      ALIST association instead of the CAR.  You can think of this as
  922.      "reverse `assq'", finding the key for a given value.
  923.  
  924.      For example:
  925.  
  926.           (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
  927.           
  928.           (rassq 'acorns trees)
  929.                => (oak . acorns)
  930.           (rassq 'spores trees)
  931.                => nil
  932.  
  933.      Note that `rassq' cannot search for a value stored in the CAR of
  934.      the CDR of an element:
  935.  
  936.           (setq colors '((rose red) (lily white) (buttercup yellow)))
  937.           
  938.           (rassq 'white colors)
  939.                => nil
  940.  
  941.      In this case, the CDR of the association `(lily white)' is not the
  942.      symbol `white', but rather the list `(white)'.  This becomes
  943.      clearer if the association is written in dotted pair notation:
  944.  
  945.           (lily white) == (lily . (white))
  946.  
  947.  - Function: remassoc KEY ALIST
  948.      This function deletes by side effect any associations with key KEY
  949.      in ALIST - i.e. it removes any elements from ALIST whose `car' is
  950.      `equal' to KEY.  The modified ALIST is returned.
  951.  
  952.      If the first member of ALIST has a `car' that is `equal' to KEY,
  953.      there is no way to remove it by side effect; therefore, write
  954.      `(setq foo (remassoc key foo))' to be sure of changing the value
  955.      of `foo'.
  956.  
  957.  - Function: remassq KEY ALIST
  958.      This function deletes by side effect any associations with key KEY
  959.      in ALIST - i.e. it removes any elements from ALIST whose `car' is
  960.      `eq' to KEY.  The modified ALIST is returned.
  961.  
  962.      This function is exactly like `remassoc', but comparisons between
  963.      KEY and keys in ALIST are done using `eq' instead of `equal'.
  964.  
  965.  - Function: remrassoc VALUE ALIST
  966.      This function deletes by side effect any associations with value
  967.      VALUE in ALIST - i.e. it removes any elements from ALIST whose
  968.      `cdr' is `equal' to VALUE.  The modified ALIST is returned.
  969.  
  970.      If the first member of ALIST has a `car' that is `equal' to VALUE,
  971.      there is no way to remove it by side effect; therefore, write
  972.      `(setq foo (remassoc value foo))' to be sure of changing the value
  973.      of `foo'.
  974.  
  975.      `remrassoc' is like `remassoc' except that it compares the CDR of
  976.      each ALIST association instead of the CAR.  You can think of this
  977.      as "reverse `remassoc'", removing an association based on its
  978.      value instead of its key.
  979.  
  980.  - Function: remrassq VALUE ALIST
  981.      This function deletes by side effect any associations with value
  982.      VALUE in ALIST - i.e. it removes any elements from ALIST whose
  983.      `cdr' is `eq' to VALUE.  The modified ALIST is returned.
  984.  
  985.      This function is exactly like `remrassoc', but comparisons between
  986.      VALUE and values in ALIST are done using `eq' instead of `equal'.
  987.  
  988.  - Function: copy-alist ALIST
  989.      This function returns a two-level deep copy of ALIST: it creates a
  990.      new copy of each association, so that you can alter the
  991.      associations of the new alist without changing the old one.
  992.  
  993.           (setq needles-per-cluster
  994.                 '((2 . ("Austrian Pine" "Red Pine"))
  995.                   (3 . ("Pitch Pine"))
  996.                   (5 . ("White Pine"))))
  997.           =>
  998.           ((2 "Austrian Pine" "Red Pine")
  999.            (3 "Pitch Pine")
  1000.            (5 "White Pine"))
  1001.           
  1002.           (setq copy (copy-alist needles-per-cluster))
  1003.           =>
  1004.           ((2 "Austrian Pine" "Red Pine")
  1005.            (3 "Pitch Pine")
  1006.            (5 "White Pine"))
  1007.           
  1008.           (eq needles-per-cluster copy)
  1009.                => nil
  1010.           (equal needles-per-cluster copy)
  1011.                => t
  1012.           (eq (car needles-per-cluster) (car copy))
  1013.                => nil
  1014.           (cdr (car (cdr needles-per-cluster)))
  1015.                => ("Pitch Pine")
  1016.           (eq (cdr (car (cdr needles-per-cluster)))
  1017.               (cdr (car (cdr copy))))
  1018.                => t
  1019.  
  1020.      This example shows how `copy-alist' makes it possible to change
  1021.      the associations of one copy without affecting the other:
  1022.  
  1023.           (setcdr (assq 3 copy) '("Martian Vacuum Pine"))
  1024.           (cdr (assq 3 needles-per-cluster))
  1025.                => ("Pitch Pine")
  1026.  
  1027.    ---------- Footnotes ----------
  1028.  
  1029.    (1) This usage of "key" is not related to the term "key sequence";
  1030. it means a value used to look up an item in a table.  In this case, the
  1031. table is the alist, and the alist associations are the items.
  1032.  
  1033. 
  1034. File: lispref.info,  Node: Property Lists,  Next: Weak Lists,  Prev: Association Lists,  Up: Lists
  1035.  
  1036. Property Lists
  1037. ==============
  1038.  
  1039.    A "property list" (or "plist") is another way of representing a
  1040. mapping from keys to values.  Instead of the list consisting of conses
  1041. of a key and a value, the keys and values alternate as successive
  1042. entries in the list.  Thus, the association list
  1043.  
  1044.      ((a . 1) (b . 2) (c . 3))
  1045.  
  1046.    has the equivalent property list form
  1047.  
  1048.      (a 1 b 2 c 3)
  1049.  
  1050.    Property lists are used to represent the properties associated with
  1051. various sorts of objects, such as symbols, strings, frames, etc.  The
  1052. convention is that property lists can be modified in-place, while
  1053. association lists generally are not.
  1054.  
  1055.    Plists come in two varieties: "normal" plists, whose keys are
  1056. compared with `eq', and "lax" plists, whose keys are compared with
  1057. `equal',
  1058.  
  1059.  - Function: valid-plist-p PLIST
  1060.      Given a plist, this function returns non-`nil' if its format is
  1061.      correct.  If it returns `nil', `check-valid-plist' will signal an
  1062.      error when given the plist; that means it's a malformed or circular
  1063.      plist or has non-symbols as keywords.
  1064.  
  1065.  - Function: check-valid-plist PLIST
  1066.      Given a plist, this function signals an error if there is anything
  1067.      wrong with it.  This means that it's a malformed or circular plist.
  1068.  
  1069. * Menu:
  1070.  
  1071. * Working With Normal Plists::       Functions for normal plists.
  1072. * Working With Lax Plists::          Functions for lax plists.
  1073. * Converting Plists To/From Alists:: Alist to plist and vice-versa.
  1074.  
  1075. 
  1076. File: lispref.info,  Node: Working With Normal Plists,  Next: Working With Lax Plists,  Up: Property Lists
  1077.  
  1078. Working With Normal Plists
  1079. --------------------------
  1080.  
  1081.  - Function: plist-get PLIST PROP &optional DEFAULT
  1082.      This function extracts a value from a property list.  The function
  1083.      returns the value corresponding to the given PROP, or DEFAULT if
  1084.      PROP is not one of the properties on the list.
  1085.  
  1086.  - Function: plist-put PLIST PROP VAL
  1087.      This function changes the value in PLIST of PROP to VAL.  If PROP
  1088.      is already a property on the list, its value is set to VAL,
  1089.      otherwise the new PROP VAL pair is added.  The new plist is
  1090.      returned; use `(setq x (plist-put x prop val))' to be sure to use
  1091.      the new value.  The PLIST is modified by side effects.
  1092.  
  1093.  - Function: plist-remprop PLIST PROP
  1094.      This function removes from PLIST the property PROP and its value.
  1095.      The new plist is returned; use `(setq x (plist-remprop x prop
  1096.      val))' to be sure to use the new value.  The PLIST is modified by
  1097.      side effects.
  1098.  
  1099.  - Function: plist-member PLIST PROP
  1100.      This function returns `t' if PROP has a value specified in PLIST.
  1101.  
  1102.    In the following functions, if optional arg NIL-MEANS-NOT-PRESENT is
  1103. non-`nil', then a property with a `nil' value is ignored or removed.
  1104. This feature is a virus that has infected old Lisp implementations (and
  1105. thus E-Lisp, due to RMS's enamorment with old Lisps), but should not be
  1106. used except for backward compatibility.
  1107.  
  1108.  - Function: plists-eq A B &optional NIL-MEANS-NOT-PRESENT
  1109.      This function returns non-`nil' if property lists A and B are `eq'
  1110.      (i.e. their values are `eq').
  1111.  
  1112.  - Function: plists-equal A B &optional NIL-MEANS-NOT-PRESENT
  1113.      This function returns non-`nil' if property lists A and B are
  1114.      `equal' (i.e. their values are `equal'; their keys are still
  1115.      compared using `eq').
  1116.  
  1117.  - Function: canonicalize-plist PLIST &optional NIL-MEANS-NOT-PRESENT
  1118.      This function destructively removes any duplicate entries from a
  1119.      plist.  In such cases, the first entry applies.
  1120.  
  1121.      The new plist is returned.  If NIL-MEANS-NOT-PRESENT is given, the
  1122.      return value may not be `eq' to the passed-in value, so make sure
  1123.      to `setq' the value back into where it came from.
  1124.  
  1125. 
  1126. File: lispref.info,  Node: Working With Lax Plists,  Next: Converting Plists To/From Alists,  Prev: Working With Normal Plists,  Up: Property Lists
  1127.  
  1128. Working With Lax Plists
  1129. -----------------------
  1130.  
  1131.    Recall that a "lax plist" is a property list whose keys are compared
  1132. using `equal' instead of `eq'.
  1133.  
  1134.  - Function: lax-plist-get LAX-PLIST PROP &optional DEFAULT
  1135.      This function extracts a value from a lax property list.  The
  1136.      function returns the value corresponding to the given PROP, or
  1137.      DEFAULT if PROP is not one of the properties on the list.
  1138.  
  1139.  - Function: lax-plist-put LAX-PLIST PROP VAL
  1140.      This function changes the value in LAX-PLIST of PROP to VAL.
  1141.  
  1142.  - Function: lax-plist-remprop LAX-PLIST PROP
  1143.      This function removes from LAX-PLIST the property PROP and its
  1144.      value.  The new plist is returned; use `(setq x (lax-plist-remprop
  1145.      x prop val))' to be sure to use the new value.  The LAX-PLIST is
  1146.      modified by side effects.
  1147.  
  1148.  - Function: lax-plist-member LAX-PLIST PROP
  1149.      This function returns `t' if PROP has a value specified in
  1150.      LAX-PLIST.
  1151.  
  1152.    In the following functions, if optional arg NIL-MEANS-NOT-PRESENT is
  1153. non-`nil', then a property with a `nil' value is ignored or removed.
  1154. This feature is a virus that has infected old Lisp implementations (and
  1155. thus E-Lisp, due to RMS's enamorment with old Lisps), but should not be
  1156. used except for backward compatibility.
  1157.  
  1158.  - Function: lax-plists-eq A B &optional NIL-MEANS-NOT-PRESENT
  1159.      This function returns non-`nil' if lax property lists A and B are
  1160.      `eq' (i.e. their values are `eq'; their keys are still compared
  1161.      using `equal').
  1162.  
  1163.  - Function: lax-plists-equal A B &optional NIL-MEANS-NOT-PRESENT
  1164.      This function returns non-`nil' if lax property lists A and B are
  1165.      `equal' (i.e. their values are `equal').
  1166.  
  1167.  - Function: canonicalize-lax-plist LAX-PLIST &optional
  1168.           NIL-MEANS-NOT-PRESENT
  1169.      This function destructively removes any duplicate entries from a
  1170.      lax plist.  In such cases, the first entry applies.
  1171.  
  1172.      The new plist is returned.  If NIL-MEANS-NOT-PRESENT is given, the
  1173.      return value may not be `eq' to the passed-in value, so make sure
  1174.      to `setq' the value back into where it came from.
  1175.  
  1176. 
  1177. File: lispref.info,  Node: Converting Plists To/From Alists,  Prev: Working With Lax Plists,  Up: Property Lists
  1178.  
  1179. Converting Plists To/From Alists
  1180. --------------------------------
  1181.  
  1182.  - Function: alist-to-plist ALIST
  1183.      This function converts association list ALIST into the equivalent
  1184.      property-list form.  The plist is returned.  This converts from
  1185.  
  1186.           ((a . 1) (b . 2) (c . 3))
  1187.  
  1188.      into
  1189.  
  1190.           (a 1 b 2 c 3)
  1191.  
  1192.      The original alist is not modified.
  1193.  
  1194.  - Function: plist-to-alist PLIST
  1195.      This function converts property list PLIST into the equivalent
  1196.      association-list form.  The alist is returned.  This converts from
  1197.  
  1198.           (a 1 b 2 c 3)
  1199.  
  1200.      into
  1201.  
  1202.           ((a . 1) (b . 2) (c . 3))
  1203.  
  1204.      The original plist is not modified.
  1205.  
  1206.    The following two functions are equivalent to the preceding two
  1207. except that they destructively modify their arguments, using cons cells
  1208. from the original list to form the new list rather than allocating new
  1209. cons cells.
  1210.  
  1211.  - Function: destructive-alist-to-plist ALIST
  1212.      This function destructively converts association list ALIST into
  1213.      the equivalent property-list form.  The plist is returned.
  1214.  
  1215.  - Function: destructive-plist-to-alist PLIST
  1216.      This function destructively converts property list PLIST into the
  1217.      equivalent association-list form.  The alist is returned.
  1218.  
  1219. 
  1220. File: lispref.info,  Node: Weak Lists,  Prev: Property Lists,  Up: Lists
  1221.  
  1222. Weak Lists
  1223. ==========
  1224.  
  1225.    A "weak list" is a special sort of list whose members are not counted
  1226. as references for the purpose of garbage collection.  This means that,
  1227. for any object in the list, if there are no references to the object
  1228. anywhere outside of the list (or other weak list or weak hash table),
  1229. that object will disappear the next time a garbage collection happens.
  1230. Weak lists can be useful for keeping track of things such as unobtrusive
  1231. lists of another function's buffers or markers.  When that function is
  1232. done with the elements, they will automatically disappear from the list.
  1233.  
  1234.    Weak lists are used internally, for example, to manage the list
  1235. holding the children of an extent - an extent that is unused but has a
  1236. parent will still be reclaimed, and will automatically be removed from
  1237. its parent's list of children.
  1238.  
  1239.    Weak lists are similar to weak hash tables (*note Weak Hash
  1240. Tables::.).
  1241.  
  1242.  - Function: weak-list-p OBJECT
  1243.      This function returns non-`nil' if OBJECT is a weak list.
  1244.  
  1245.    Weak lists come in one of four types:
  1246.  
  1247. `simple'
  1248.      Objects in the list disappear if not referenced outside of the
  1249.      list.
  1250.  
  1251. `assoc'
  1252.      Objects in the list disappear if they are conses and either the
  1253.      car or the cdr of the cons is not referenced outside of the list.
  1254.  
  1255. `key-assoc'
  1256.      Objects in the list disappear if they are conses and the car is not
  1257.      referenced outside of the list.
  1258.  
  1259. `value-assoc'
  1260.      Objects in the list disappear if they are conses and the cdr is not
  1261.      referenced outside of the list.
  1262.  
  1263.  - Function: make-weak-list &optional TYPE
  1264.      This function creates a new weak list of type TYPE.  TYPE is a
  1265.      symbol (one of `simple', `assoc', `key-assoc', or `value-assoc',
  1266.      as described above) and defaults to `simple'.
  1267.  
  1268.  - Function: weak-list-type WEAK
  1269.      This function returns the type of the given weak-list object.
  1270.  
  1271.  - Function: weak-list-list WEAK
  1272.      This function returns the list contained in a weak-list object.
  1273.  
  1274.  - Function: set-weak-list-list WEAK NEW-LIST
  1275.      This function changes the list contained in a weak-list object.
  1276.  
  1277. 
  1278. File: lispref.info,  Node: Sequences Arrays Vectors,  Next: Symbols,  Prev: Lists,  Up: Top
  1279.  
  1280. Sequences, Arrays, and Vectors
  1281. ******************************
  1282.  
  1283.    Recall that the "sequence" type is the union of four other Lisp
  1284. types: lists, vectors, bit vectors, and strings.  In other words, any
  1285. list is a sequence, any vector is a sequence, any bit vector is a
  1286. sequence, and any string is a sequence.  The common property that all
  1287. sequences have is that each is an ordered collection of elements.
  1288.  
  1289.    An "array" is a single primitive object that has a slot for each
  1290. elements.  All the elements are accessible in constant time, but the
  1291. length of an existing array cannot be changed.  Strings, vectors, and
  1292. bit vectors are the three types of arrays.
  1293.  
  1294.    A list is a sequence of elements, but it is not a single primitive
  1295. object; it is made of cons cells, one cell per element.  Finding the
  1296. Nth element requires looking through N cons cells, so elements farther
  1297. from the beginning of the list take longer to access.  But it is
  1298. possible to add elements to the list, or remove elements.
  1299.  
  1300.    The following diagram shows the relationship between these types:
  1301.  
  1302.                ___________________________________
  1303.               |                                   |
  1304.               |          Sequence                 |
  1305.               |  ______   ______________________  |
  1306.               | |      | |                      | |
  1307.               | | List | |         Array        | |
  1308.               | |      | |  ________   _______  | |
  1309.               | |______| | |        | |       | | |
  1310.               |          | | Vector | | String| | |
  1311.               |          | |________| |_______| | |
  1312.               |          |  __________________  | |
  1313.               |          | |                  | | |
  1314.               |          | |    Bit Vector    | | |
  1315.               |          | |__________________| | |
  1316.               |          |______________________| |
  1317.               |___________________________________|
  1318.  
  1319.    The elements of vectors and lists may be any Lisp objects.  The
  1320. elements of strings are all characters.  The elements of bit vectors
  1321. are the numbers 0 and 1.
  1322.  
  1323. * Menu:
  1324.  
  1325. * Sequence Functions::    Functions that accept any kind of sequence.
  1326. * Arrays::                Characteristics of arrays in XEmacs Lisp.
  1327. * Array Functions::       Functions specifically for arrays.
  1328. * Vectors::               Special characteristics of XEmacs Lisp vectors.
  1329. * Vector Functions::      Functions specifically for vectors.
  1330. * Bit Vectors::           Special characteristics of XEmacs Lisp bit vectors.
  1331. * Bit Vector Functions::  Functions specifically for bit vectors.
  1332.  
  1333.